package com.ran.controller;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 *中转获取数据
 * 接收来自home.jsp获取到的search数据，发送给update.jsp
 * ---已弃用---
 */
//@WebServlet("/getdata")
public class getdata extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
//        获取数据,因为这里是传递给update.jsp作渲染，所以不必再强转为int
        String reenames = req.getParameter("ename");
        String egendars = req.getParameter("egendar");
        String depids = req.getParameter("depid");
//        将数据存储进一个哈希表中
        HashMap<String, Object> hsmp = new HashMap<>();
        hsmp.put("row1",reenames);
        hsmp.put("row2",egendars);
        hsmp.put("row3",depids);
//        将哈希表转化为json对象并作响应准备
        JSONObject jsonObject = new JSONObject(hsmp);
        System.out.println("getdata内的tojsonstring:"+jsonObject.toJSONString());
        resp.getWriter().write(jsonObject.toJSONString());
    }
}
